var assert = require('assert');
let Validator = require('../index.js')
let Rule = require("../src/rule.js")
class CustomRule extends Rule{
	name(){
		return 'custom'
	}
	check(column,value,values,params){
		return typeof value !== 'undefined' && value !== '' && value !== null
	}
}

let name = "custom校验"
let validator = new Validator({rules:{custom:CustomRule}})
let test=function(data,rules,messages,attributes,expect,message){
	let check = validator.check(data,rules,messages,attributes)
	describe(name, function() {
	  it('参数:'+JSON.stringify(data)+"|规则:"+JSON.stringify(rules), function() {
	      assert.equal(check.passes(), expect);
	      if(!expect){
	      	assert.equal(check.error(), message);
	      }
	  });
	});
}
let run = function(data){
	for(var i in data){
		test(data[i]["data"],data[i]["rules"],data[i]["messages"],data[i]["attributes"],data[i]["expect"],data[i]["message"])
	}
}
run([
	{
		data: {test: null},
		rules: {test: "custom"},
		messages: {custom: ":attr不通过"},
		attributes: {test: "测试"},
		expect: false,
		message: "测试不通过"
	},
	{
		data: {test: 123},
		rules: {test: "custom"},
		messages: {custom: ":attr不通过"},
		attributes: {test: "测试"},
		expect: true,
		message: null
	}
]);